package com.xbts.web.controller.party;

import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.core.page.TableDataInfo;
import com.xbts.common.enums.BusinessType;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.system.domain.PartyActiveManage;
import com.xbts.system.service.IPartyActiveManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动管理Controller
 *
 * @author xbts
 * @date 2023-06-12
 */
@Api(tags = "活动管理")
@RestController
@RequestMapping("/party/active/manage")
public class PartyActiveManageController extends BaseController {

    @Autowired
    private IPartyActiveManageService partyActiveManageService;

    /**
     * 查询活动管理列表
     */
    @ApiOperation("查询活动管理列表")
//    @PreAuthorize("@ss.hasPermi('party:manage:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody PartyActiveManage partyActiveManage) {
        startPage(partyActiveManage);
        List<PartyActiveManage> list = partyActiveManageService.selectPartyActiveManageList(partyActiveManage);
        return getDataTable(list);
    }

    /**
     * 导出活动管理列表
     */
    @ApiOperation("导出活动管理列表")
//    @PreAuthorize("@ss.hasPermi('party:manage:export')")
    @Log(title = "活动管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody PartyActiveManage partyActiveManage) {
        List<PartyActiveManage> list = partyActiveManageService.selectPartyActiveManageList(partyActiveManage);
        ExcelUtil<PartyActiveManage> util = new ExcelUtil<PartyActiveManage>(PartyActiveManage.class);
        util.exportExcel(response, list, "活动管理数据");
    }

    /**
     * 获取活动管理详细信息
     */
    @ApiOperation("获取活动管理详细信息")
    @ApiImplicitParam(name = "activityCode", value = "活动管理ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermi('party:manage:query')")
    @GetMapping(value = "/{activityCode}")
    public AjaxResult getInfo(@PathVariable("activityCode") String activityCode) {
        return success(partyActiveManageService.selectPartyActiveManageByActivityCode(activityCode));
    }

    /**
     * 新增活动管理
     */
    @ApiOperation("新增活动管理")
//    @PreAuthorize("@ss.hasPermi('party:manage:add')")
    @Log(title = "活动管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PartyActiveManage partyActiveManage) {
        return toAjax(partyActiveManageService.insertPartyActiveManage(partyActiveManage));
    }

    /**
     * 修改活动管理
     */
    @ApiOperation("修改活动管理")
//    @PreAuthorize("@ss.hasPermi('party:manage:edit')")
    @Log(title = "活动管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PartyActiveManage partyActiveManage) {
        return toAjax(partyActiveManageService.updatePartyActiveManage(partyActiveManage));
    }

    /**
     * 删除活动管理
     */
    @ApiOperation("删除活动管理")
    @ApiImplicitParam(name = "activityCodes", value = "活动管理ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermi('party:manage:remove')")
    @Log(title = "活动管理", businessType = BusinessType.DELETE)
    @PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> activityCodes) {
        return toAjax(partyActiveManageService.deletePartyActiveManageByActivityCodes(activityCodes));
    }
}
